<template>
  <div class="app-container">
    <div class="table-operation">
      <span>
        <el-button
          v-if="hasBtn['新增']"
          type="primary"
          icon="el-icon-circle-plus-outline"
          @click="c"
        >
          新增
        </el-button>
      </span>
      <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      />
    </div>

    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column label="公告弹框标题" prop="title" />
      <el-table-column label="有公告详情" prop="detailFlag">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.detailFlag == 1" type="success">是</el-tag>
          <el-tag v-if="scope.row.detailFlag == 0" type="info">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="详情按钮文字" prop="detailTxt" />
      <el-table-column label="详情标题" prop="detailTitle" />
      <el-table-column label="状态" align="center">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch
            v-bind="popSwitchProps(status)"
            @change="updateStatus({ id, status: status ^ 1 })"
          />
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="{ row: { id } }">
          <KiPopButton v-if="hasBtn['查看']" @click="r({ id })">
            查看
          </KiPopButton>
          <KiPopButton v-if="hasBtn['编辑']" @click="u({ id })">
            编辑
          </KiPopButton>
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog
      :title="formTitle"
      :show.sync="form.show"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      ref="formRef"
      :loading="form.loading"
    >
      <template #el-form>
        <el-form-item label="公告弹框标题" prop="title" verify>
          <el-input
            v-model="form.data.title"
            clearable
            maxlength="10"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="公告弹框内容" prop="content" verify>
          <el-input
            v-model="form.data.content"
            type="textarea"
            :autosize="{ minRows: 3 }"
            clearable
            maxlength="500"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="有无公告详情" prop="detailFlag" verify>
          <el-switch
            v-model="form.data.detailFlag"
            :active-value="1"
            :inactive-value="0"
          />
        </el-form-item>
        <div v-show="form.data.detailFlag === 1">
          <el-form-item label="详情按钮文字" prop="detailTxt" verify>
            <el-input
              v-model="form.data.detailTxt"
              clearable
              maxlength="6"
              show-word-limit
            />
          </el-form-item>
          <el-form-item label="详情标题" prop="detailTitle" verify>
            <el-input
              v-model="form.data.detailTitle"
              clearable
              maxlength="20"
              show-word-limit
            />
          </el-form-item>
          <el-form-item label="详情内容" prop="detailContent" verify>
            <MiniMCE v-model="form.data.detailContent" :disabled="form.status === 'r'"/>
          </el-form-item>
        </div>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'

export default {
  mixins: [pageMixin],
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'sot-admin-api/reservation/reservation-notice',
      axiosConfig: {
        getList: {
          url: 'queryForList'
        }
      },
      list: {
        dataAt: 'data'
      }
    }),
  methods: {}
}
</script>

<style lang="scss" scoped></style>
